using System;
using System.Collections.Generic;
using System.Linq;
namespace DIS_WEB_Client.Controllers
{
	#region using
	using System.Web.Mvc;
	using DIS_WEB_Client.ViewModels;
	using DIS_WEB_Client.Repositories;
	using DIS_WEB_Client.Helpers;
	using System.Web.Security;
    using DIS_WEB_Client.DIS_BUS_WS;
using System.Globalization;
	#endregion
	public partial class AdminController: BaseController
	{
        public ActionResult CancelEditingOrders(string idorder, string from, string to)
		{
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
                IDOrder = int.Parse(idorder),
                IntID = int.Parse(idorder),
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
            };
            return View("Revenue", CreateViewModel(data));
		}

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult UpdateOrders(FormCollection forms)
        {
            var from = forms.GetValues("Orders_From")[0];
            var to = forms.GetValues("Orders_To")[0];

            var orders = _repOrders.SelectByID(int.Parse(forms.GetValues("Orders_ID")[0]));
            orders.IsVerified = bool.Parse(forms.GetValues("IsVerified")[0]);
            orders.IsShipped = bool.Parse(forms.GetValues("IsShipped")[0]);
            orders.IsPaid = bool.Parse(forms.GetValues("IsPaid")[0]);

            var result = _repOrders.Update(orders);
            
            var data = new DataTransferViewModel
            {
                IDOrder = orders.ID,
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
            };
            return View("Revenue", CreateViewModel(data));
        }

        public ActionResult Revenue()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_REVENUE,
            };
            return View(CreateViewModel(data));
        }

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Revenue(FormCollection forms)
        {
            var from = forms.GetValues("Revenue_From")[0];
            var to = forms.GetValues("Revenue_To")[0];

            string[] supportedFormats = new String[] { "MM/dd/yyyy" };
            CultureInfo myCIintl = new CultureInfo( "en", false );

            DateTime startDate = DateTime.ParseExact(
                from, supportedFormats,
                myCIintl,
                DateTimeStyles.None);

            DateTime endDate = DateTime.ParseExact(
                to, supportedFormats,
                myCIintl,
                DateTimeStyles.None);

            var data = new DataTransferViewModel
            {
                From = startDate,
                To = endDate,
                EnumViewModelType = EnumViewModel.ADMIN_ORDERS_REVENUE_EXECUTE,
            };
            return View("Revenue", CreateViewModel(data));
        }

        public ActionResult SelectOrderDetail(string idorder, string from, string to)
        {
            var data = new DataTransferViewModel
            {
                IDOrder = int.Parse(idorder),
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
            };
            return View("Revenue", CreateViewModel(data));
        }

        public ActionResult EditOrders(string idorder, string from, string to)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
                IDOrder = int.Parse(idorder),
                IntID = int.Parse(idorder),
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
            };
            return View("EditOrders", CreateViewModel(data));
        }
	}
}